/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.belfalas.simy86.operadores;

import org.belfalas.simy86.Registradores;
import org.belfalas.simy86.Y86;

/**
 *
 * @author belfalas
 */
public class PUSHL extends Operador{

    public void fetch(org.belfalas.simy86.Operador_Stat stat) {
        stat.reg = Y86.memoria.readUnsignedByte(stat.pc+1);
        stat.rA = getRA(stat.reg);
        stat.rA.incUsage();
        stat.rB = Registradores.ESP;
        stat.rB.incUsage();
        stat.valP = stat.pc+2;
        stat.predicted_pc = stat.valP;
    }

    public void decode(org.belfalas.simy86.Operador_Stat stat) {
       stat.valA = stat.rA.reg;       
       stat.valB = stat.rB.reg;
    }

    public void execute(org.belfalas.simy86.Operador_Stat stat) {
        stat.rA.decUsage();
        stat.valE = stat.valB + (-4);
    }

    public void memory(org.belfalas.simy86.Operador_Stat stat) {
        Y86.memoria.writeSignedWord(stat.valA, stat.valE);
        //if (Y86.tab_numbers < 9) for (int i=0; i<Y86.tab_numbers; i++) System.out.print(Y86.tab);
        //if (Y86.tab_numbers < 9) System.out.println(stat.rA+"="+stat.valA+"->"+stat.valE);
        Y86.tab_numbers++;
    }

    public void writeback(org.belfalas.simy86.Operador_Stat stat) {
        stat.rB.reg = stat.valE;
        stat.rB.decUsage();
        //PC.position = stat.valP;
    }

    
}
